package com.jackrain.nea.core.mapper;

import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

@Mapper
@Component
public interface DirectoryMapper {

    @Update("update directory set description = (select description from ad_table where id = #{tableid}) where ad_table_id = #{tableid}")
    int syncTableDescription(long tableid);

    @Update("update directory set AD_TABLECATEGORY_ID = (select AD_TABLECATEGORY_ID from ad_table where id = #{tableid}) where ad_table_id = #{tableid}")
    int syncAdTableCategoryId(long tableid);

    @Select("select count(*) from directory where id = #{directoryId} and ad_table_id = #{tableId}")
    int countWithTable(@Param("directoryId") long directoryId, @Param("tableId") long tableId);

    @Delete("delete from directory where id = #{directoryId}")
    int delete(long directoryId);

    @Select("select * from directory where id = (select DIRECTORY_ID from ad_table where id = #{tableId})")
    JSONObject selectFullByTableId(long tableId);

    @Select("select count(1) from directory where name = #{name} limit 1")
    boolean exists(String name);
}
